package cn.edu.bit.lixin.blog.biz;

import java.util.List;

import cn.edu.bit.lixin.blog.dao.ReplyDAO;
import cn.edu.bit.lixin.blog.entity.Reply;

public class ReplyManager {
	private ReplyDAO dao;

	public ReplyDAO getDao() {
		return dao;
	}

	public void setDao(ReplyDAO dao) {
		this.dao = dao;
	}
	
	/**
	 * 根据给定的blogid，返回这篇日志的所有回复
	 * @param blogid
	 * @return
	 */
	public List<Reply> getSpecificReplies(int blogid){
		return dao.getSpecificReplies(blogid);
	}
	
	/**
	 * 给定指定的replyid,得到这个reply
	 * @param replyid
	 * @return
	 */
	public Reply getSpecificReply(int replyid){
		return (Reply)dao.findById(Reply.class, replyid);
	}
	
	
	public boolean saveReply(Reply reply){
		try{
			dao.save(reply);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	/**
	 * 判断验证码是否相等
	 * @param verifyCodeFrom 表单中输入的验证码
	 * @param verifyCodeSession session中的验证码
	 * @return
	 */
	public boolean judgeVerifyCode(String verifyCodeFrom, String verifyCodeSession){
		if (verifyCodeFrom.equalsIgnoreCase(verifyCodeSession)){
			return true;
		}
		return false;
	}
	
	/**
	 * 删除指定的留言
	 * @param replyid
	 * @return
	 */
	public boolean deleteReply(int replyid){
		Reply reply = this.getSpecificReply(replyid);
		
		try{
			dao.delete(reply);
			return true;
		}catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}
}
